import axios from 'axios'

const { VITE_PUBLIC_PATH } = import.meta.env

/** 获取项目动态全局配置 */
export async function getPlatformConfig(): Promise<PlatformConfigs> {
  return axios({
    method: 'get',
    url: `${VITE_PUBLIC_PATH}platform-config.json`,
    timeout: 10000,
  })
    .then(({ data: config }) => {
      if (useConfigStoreHook().platformConfig.Version === undefined) {
        useConfigStoreHook().setConfig(config)
      }
      return config
    })
    .catch(() => {
      throw new Error('请在public文件夹下添加platform-config.json配置文件')
    })
}
